#define DEBUG
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=500, mods=998244353;

class Side {
public:
  int u, v;

  static bool cmp(Side a, Side b) {
    return a.v<b.v;
  }
};

class Tree {
public:
  int n, m, ind[maxn+1], to[2*maxn-1], link[2*maxn-1], node[maxn+1], fa[maxn+1];

  void addSide(int x, int y) {
    m++;
    to[m] = y;
    link[m] = ind[x];
    ind[x] = m;
  }

  void build(int o, int fa) {
    this->fa[o] = fa;
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
	build(to[i], o);
      }
    }
  }

  int getNum(int o, bool book[]) {
    static int ret;
    ret = o==1 ? node[o] : ret*10+node[o];
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa[o] && book[to[i]]) {
	getNum(to[i], book);
      }
    }
    return ret;
  }
};

int maxdigit(int n, int k) {
  int ret=0;
  for (int i=1; i<=n; i*=k) {
    ret = max(ret, n/i%k);
  }
  return ret;
}

bool check(int n, int k) {
  int a=1;
  for (; n>=a; a=a+maxdigit(a, k));
  return n==a;
}

long long solve(int o, int k, Tree &t) {
  static bool book[maxn+1];
  long long ret=0;
  if (o<=t.n) {
    book[o] = true;
    ret = (ret+solve(o+1, k, t))%mods;
    book[o] = false;
    ret = (ret+solve(o+1, k, t))%mods;
  } else {
    bool flag=true;
    for (int i=1; flag && i<=t.n; i++) {
      flag = !(book[i] && !book[t.fa[i]]);
    }
    if (flag && check(t.getNum(1, book), k)) {
      return 1;
    }
  }
  return ret;
}

int main() {
  freopen("buried.in", "r", stdin);
  freopen("buried.out", "w", stdout);

  static Tree tree;
  int n, k;
  scanf("%d %d", &n, &k);
  tree.n = n;
  for (int i=1; i<=n; i++) {
    scanf("%d", &tree.node[i]);
  }

  static Side sides[2*maxn-1];
  for (int i=1; i<n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    sides[i*2-1].u=x, sides[i*2-1].v=y;
    sides[i*2].u=y, sides[i*2].v=x;
  }
  sort(sides+1, sides+2*n-1, Side::cmp);

  for (int i=2*n-1; i>0; i--) {
    tree.addSide(sides[i].u, sides[i].v);
  }

  tree.build(1, 1);

  printf("%lld", solve(1, k, tree));

  fclose(stdin);
  fclose(stdout);
  return 0;
}
